package com.zrm.zfcrpa.dao.mapper.loginMapper;

import com.alibaba.fastjson.JSONObject;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.stereotype.Repository;

import javax.websocket.server.ServerEndpoint;

@Repository
@Mapper
public interface LoginDao {

    @Insert("insert into zrm_login_info(zrm_user_account,zrm_login_ip,zrm_login_type) values(#{userName},#{ip},#{loginType})")
    void addLoginInfo(@Param("ip") String ip,@Param("userName") String userName,@Param("loginType") String loginType);

    @Select("select zrm_user_account zrmUserAccount, \n" +
            "                   zrm_user_name zrmUserName, \n" +
            "                   zrm_role_id zrmRoleId, \n" +
            "                   zrm_bus_bank_id zrmBusBankId, \n" +
            "                   zrm_bus_bank_net_id zrmBusBankNetId, \n" +
            "                   zrm_phone_number zrmPhoneNumber, \n" +
            "                   zrm_position zrmPosition, \n" +
            "                   zrm_pboc_area zrmPbocArea, \n" +
            "                   zrm_street_area zrmStreetArea, \n" +
            "                   zrm_address zrmAddress, \n" +
            "                   zrm_user_status zrmUserStatus, \n" +
            "                   zrm_creator zrmCreator, \n" +
            "                   zrm_last_updator zrmLastUpdator, \n" +
            "                   zrm_translate_code zrmTranslateCode,  \n" +
            "                   zrm_translate_value zrmTranslateValue,  \n" +
            "                   zrm_translate_descr zrmTranslateDescr \n" +
            "            from zrm_user_info t \n" +
            "            left join zrm_public_translate t1 on t.zrm_role_id = t1.zrm_translate_value and t1.zrm_translate_code = 'zrm_role_id'\n" +
            "            where t.zrm_user_name =  #{userName} and zrm_user_status = '0' ")
    JSONObject getUserInfo(@Param("userName") String userName);

    @Select("select zrm_user_name zrmUserName, \n" +
            "       zrm_password zrmPassword, \n" +
            "       zrm_translate_descr zrmTranslateDescr \n" +
            "       from zrm_user_info t \n" +
            "left join zrm_public_translate t1 on t.zrm_role_id = t1.zrm_translate_value and t1.zrm_translate_code = 'zrm_role_id'\n" +
            "where t.zrm_user_name =  #{userName} and zrm_user_status = '0' ")
    JSONObject doLogin(@Param("userName") String userName);

    @Select("select zrm_user_account from zrm_user_info t where zrm_user_account = #{mobile}")
    String isUser(String mobile);

    void addMobileUser();
}
